home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / fax / src / port / generic / GCC-PATCH next >
Text File  |  1994-08-01  |  11KB  |  321 lines

  1. Fri Apr  9 20:03:38 1993  Jim Wilson  (wilson@wookumz.gnu.ai.mit.edu)
  2.  
  3.     * c-typeck.c (free_tree_list): New variable.
  4.     (digest_init): Set free_tree_list.
  5.     (process_init_constructor): Use add_double to do arithmetic with
  6.     double integers instead of using fold/build to to arithmetic in
  7.     type of array index.  Use free_tree_list when available instead of
  8.     generating a new tree_list.
  9.  
  10. *** c-typeck.c.orig    Thu Nov 26 12:30:00 1992
  11. --- c-typeck.c    Sat Apr 17 22:12:17 1993
  12. *************** pedwarn_init (format, local, ofwhat)
  13. *** 4521,4526 ****
  14. --- 4521,4540 ----
  15.     pedwarn (format, buffer);
  16.   }
  17.   
  18. + /* Keep a pointer to the last free TREE_LIST node as we digest an initializer,
  19. +    so that we can reuse it.  This is set in digest_init, and used in
  20. +    process_init_constructor.
  21. +    We will never keep more than one free TREE_LIST node here.  This is for
  22. +    two main reasons.  First, we take elements off the old list and add them
  23. +    to the new list one at a time, thus there should never be more than
  24. +    one free TREE_LIST at a time, and thus even if there is, we will never
  25. +    need more than one.  Secondly, to avoid dangling pointers to freed obstacks,
  26. +    we want to always ensure that we have either a pointer to a valid TREE_LIST
  27. +    within the current initializer, or else a pointer to null.  */
  28. + static tree free_tree_list = NULL_TREE;
  29.   /* Digest the parser output INIT as an initializer for type TYPE.
  30.      Return a C expression of type TYPE to represent the initial value.
  31.   
  32. *************** digest_init (type, init, tail, require_c
  33. *** 4554,4566 ****
  34.     tree inside_init = init;
  35.   
  36.     /* By default, assume we use one element from a list.
  37. !      We correct this later in the sole case where it is not true.  */
  38.   
  39.     if (tail)
  40.       {
  41.         old_tail_contents = *tail;
  42.         *tail = TREE_CHAIN (*tail);
  43.       }
  44.   
  45.     if (init == error_mark_node)
  46.       return init;
  47. --- 4568,4588 ----
  48.     tree inside_init = init;
  49.   
  50.     /* By default, assume we use one element from a list.
  51. !      We correct this later in the cases where it is not true.
  52. !      Thus, we update TAIL now to point to the next element, and save the
  53. !      old value in OLD_TAIL_CONTENTS.  If we didn't actually use the first
  54. !      element, then we will reset TAIL before proceeding.  FREE_TREE_LIST
  55. !      is handled similarly.  */
  56.   
  57.     if (tail)
  58.       {
  59.         old_tail_contents = *tail;
  60.         *tail = TREE_CHAIN (*tail);
  61. +       free_tree_list = old_tail_contents;
  62.       }
  63. +   else
  64. +     free_tree_list = 0;
  65.   
  66.     if (init == error_mark_node)
  67.       return init;
  68. *************** digest_init (type, init, tail, require_c
  69. *** 4737,4742 ****
  70. --- 4759,4765 ----
  71.         else if (tail != 0)
  72.       {
  73.         *tail = old_tail_contents;
  74. +       free_tree_list = NULL_TREE;
  75.         result = process_init_constructor (type, NULL_TREE, tail,
  76.                            require_constant,
  77.                            constructor_constant, ofwhat);
  78. *************** digest_init (type, init, tail, require_c
  79. *** 4833,4838 ****
  80. --- 4856,4862 ----
  81.         else if (tail != 0)
  82.       {
  83.         *tail = old_tail_contents;
  84. +       free_tree_list = NULL_TREE;
  85.         return process_init_constructor (type, NULL_TREE, tail,
  86.                          constructor_constant,
  87.                          constructor_constant, ofwhat);
  88. *************** process_init_constructor (type, init, el
  89. *** 4917,4954 ****
  90.   
  91.     if (TREE_CODE (type) == ARRAY_TYPE)
  92.       {
  93. !       tree min_index, max_index, current_index, members_index;
  94. !       tree bound_type;
  95. !       tree one;
  96.         /* These are non-zero only within a range initializer.  */
  97.         tree start_index = 0, end_index = 0;
  98.         /* Within a range, this is the value for the elts in the range.  */
  99.         tree range_val = 0;
  100.   
  101.         /* If we have array bounds, set our bounds from that.  Otherwise,
  102. !      we have a lower bound of zero and an unknown upper bound.  Also
  103. !      set the type of the bounds; use "int" as default.  */
  104.         if (TYPE_DOMAIN (type))
  105.       {
  106. !       min_index = members_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
  107.         max_index = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
  108. -       bound_type = TREE_TYPE (min_index);
  109.       }
  110.         else
  111.       {
  112. !       min_index = members_index = integer_zero_node;
  113.         max_index = 0;
  114. -       bound_type = integer_type_node;
  115.       }
  116.   
  117. !       one = convert (bound_type, integer_one_node);
  118.   
  119.         /* Don't leave the loop based on index if the next item has an explicit
  120.        index value that will override it. */
  121.   
  122. !       for (current_index = min_index; tail != 0 || end_index;
  123. !        current_index = fold (build (PLUS_EXPR, bound_type,
  124. !                     current_index, one)))
  125.       {
  126.         register tree next1 = 0;
  127.   
  128. --- 4941,4987 ----
  129.   
  130.     if (TREE_CODE (type) == ARRAY_TYPE)
  131.       {
  132. !       tree min_index, max_index;
  133.         /* These are non-zero only within a range initializer.  */
  134.         tree start_index = 0, end_index = 0;
  135.         /* Within a range, this is the value for the elts in the range.  */
  136.         tree range_val = 0;
  137. +       /* Do arithmetic using double integers, but don't use fold/build,
  138. +      because these allocate a new tree object everytime they are called,
  139. +      thus resulting in gcc using too much memory for large
  140. +      initializers.  */
  141. +       union tree_node current_index_node, members_index_node;
  142. +       tree current_index = ¤t_index_node;
  143. +       tree members_index = &members_index_node;
  144. +       TREE_TYPE (current_index) = integer_type_node;
  145. +       TREE_TYPE (members_index) = integer_type_node;
  146.   
  147.         /* If we have array bounds, set our bounds from that.  Otherwise,
  148. !      we have a lower bound of zero and an unknown upper bound.  */
  149.         if (TYPE_DOMAIN (type))
  150.       {
  151. !       min_index = TYPE_MIN_VALUE (TYPE_DOMAIN (type));
  152.         max_index = TYPE_MAX_VALUE (TYPE_DOMAIN (type));
  153.       }
  154.         else
  155.       {
  156. !       min_index = integer_zero_node;
  157.         max_index = 0;
  158.       }
  159.   
  160. !       TREE_INT_CST_LOW (members_index) = TREE_INT_CST_LOW (min_index);
  161. !       TREE_INT_CST_HIGH (members_index) = TREE_INT_CST_HIGH (min_index);
  162.   
  163.         /* Don't leave the loop based on index if the next item has an explicit
  164.        index value that will override it. */
  165.   
  166. !       for (TREE_INT_CST_LOW (current_index) = TREE_INT_CST_LOW (min_index),
  167. !        TREE_INT_CST_HIGH (current_index) = TREE_INT_CST_HIGH (min_index);
  168. !        tail != 0 || end_index;
  169. !        add_double (TREE_INT_CST_LOW (current_index),
  170. !                TREE_INT_CST_HIGH (current_index), 1, 0,
  171. !                &TREE_INT_CST_LOW (current_index),
  172. !                &TREE_INT_CST_HIGH (current_index)))
  173.       {
  174.         register tree next1 = 0;
  175.   
  176. *************** process_init_constructor (type, init, el
  177. *** 5095,5114 ****
  178.            Make the list longer if necessary.  */
  179.         while (! tree_int_cst_lt (current_index, members_index))
  180.           {
  181. !           members = tree_cons (NULL_TREE, NULL_TREE, members);
  182. !           members_index = fold (build (PLUS_EXPR, bound_type,
  183. !                        members_index, one));
  184.           }
  185.   
  186.         {
  187.           tree temp;
  188. !         tree idx;
  189.   
  190.           temp = members;
  191. !         for (idx = fold (build (MINUS_EXPR, bound_type,
  192. !                     members_index, one));
  193.            tree_int_cst_lt (current_index, idx);
  194. !          idx = fold (build (MINUS_EXPR, bound_type, idx, one)))
  195.             temp = TREE_CHAIN (temp);
  196.           TREE_VALUE (temp) = next1;
  197.         }
  198. --- 5128,5165 ----
  199.            Make the list longer if necessary.  */
  200.         while (! tree_int_cst_lt (current_index, members_index))
  201.           {
  202. !           if (free_tree_list)
  203. !         {
  204. !           TREE_CHAIN (free_tree_list) = members;
  205. !           TREE_PURPOSE (free_tree_list) = NULL_TREE;
  206. !           TREE_VALUE (free_tree_list) = NULL_TREE;
  207. !           members = free_tree_list;
  208. !           free_tree_list = NULL_TREE;
  209. !         }
  210. !           else
  211. !         members = tree_cons (NULL_TREE, NULL_TREE, members);
  212. !           add_double (TREE_INT_CST_LOW (members_index),
  213. !               TREE_INT_CST_HIGH (members_index), 1, 0,
  214. !               &TREE_INT_CST_LOW (members_index),
  215. !               &TREE_INT_CST_HIGH (members_index));
  216.           }
  217.   
  218.         {
  219.           tree temp;
  220. !         union tree_node idx_node;
  221. !         tree idx = &idx_node;
  222. !         TREE_TYPE (idx) = integer_type_node;
  223.   
  224.           temp = members;
  225. !         for (add_double (TREE_INT_CST_LOW (members_index),
  226. !                  TREE_INT_CST_HIGH (members_index), -1, -1,
  227. !                  &TREE_INT_CST_LOW (idx),
  228. !                  &TREE_INT_CST_HIGH (idx));
  229.            tree_int_cst_lt (current_index, idx);
  230. !          add_double (TREE_INT_CST_LOW (idx),
  231. !                  TREE_INT_CST_HIGH (idx), -1, -1,
  232. !                  &TREE_INT_CST_LOW (idx),
  233. !                  &TREE_INT_CST_HIGH (idx)))
  234.             temp = TREE_CHAIN (temp);
  235.           TREE_VALUE (temp) = next1;
  236.         }
  237. *************** process_init_constructor (type, init, el
  238. *** 5196,5202 ****
  239.            Make the list longer if necessary.  */
  240.         while (i >= members_length)
  241.           {
  242. !           members = tree_cons (NULL_TREE, NULL_TREE, members);
  243.             members_length++;
  244.           }
  245.         {
  246. --- 5247,5262 ----
  247.            Make the list longer if necessary.  */
  248.         while (i >= members_length)
  249.           {
  250. !           if (free_tree_list)
  251. !         {
  252. !           TREE_CHAIN (free_tree_list) = members;
  253. !           TREE_PURPOSE (free_tree_list) = NULL_TREE;
  254. !           TREE_VALUE (free_tree_list) = NULL_TREE;
  255. !           members = free_tree_list;
  256. !           free_tree_list = NULL_TREE;
  257. !         }
  258. !           else
  259. !         members = tree_cons (NULL_TREE, NULL_TREE, members);
  260.             members_length++;
  261.           }
  262.         {
  263. *************** process_init_constructor (type, init, el
  264. *** 5284,5291 ****
  265.         else if (!TREE_CONSTANT (next1))
  266.       allconstant = 0;
  267.         else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
  268. !     allsimple = 0;
  269. !       members = tree_cons (field, next1, members);
  270.       }
  271.   
  272.     /* If arguments were specified as a list, just remove the ones we used.  */
  273. --- 5344,5360 ----
  274.         else if (!TREE_CONSTANT (next1))
  275.       allconstant = 0;
  276.         else if (initializer_constant_valid_p (next1, TREE_TYPE (next1)) == 0)
  277. !     allsimple = 0; 
  278. !      if (free_tree_list)
  279. !     {
  280. !       TREE_CHAIN (free_tree_list) = members;
  281. !       TREE_PURPOSE (free_tree_list) = field;
  282. !       TREE_VALUE (free_tree_list) = next1;
  283. !       members = free_tree_list;
  284. !       free_tree_list = NULL_TREE;
  285. !     }
  286. !       else
  287. !     members = tree_cons (field, next1, members);
  288.       }
  289.   
  290.     /* If arguments were specified as a list, just remove the ones we used.  */
  291. *************** process_init_constructor (type, init, el
  292. *** 5316,5322 ****
  293.     if (erroneous)
  294.       return error_mark_node;
  295.   
  296. !   result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
  297.     if (allconstant) TREE_CONSTANT (result) = 1;
  298.     if (allconstant && allsimple) TREE_STATIC (result) = 1;
  299.     return result;
  300. --- 5385,5400 ----
  301.     if (erroneous)
  302.       return error_mark_node;
  303.   
  304. !   if (elts)
  305. !     result = build (CONSTRUCTOR, type, NULL_TREE, nreverse (members));
  306. !   else
  307. !     {
  308. !       result = init;
  309. !       CONSTRUCTOR_ELTS (result) = nreverse (members);
  310. !       TREE_TYPE (result) = type;
  311. !       TREE_CONSTANT (result) = 0;
  312. !       TREE_STATIC (result) = 0;
  313. !     }
  314.     if (allconstant) TREE_CONSTANT (result) = 1;
  315.     if (allconstant && allsimple) TREE_STATIC (result) = 1;
  316.     return result;
  317.